// pages/tobeTzFirstStep/tobeTzFirstStep.js
var common_js = require("../../utils/common.js");
var ubt_js = require("../../utils/ubt.js");
var name_js = require("../../utils/ubtButtonName.js");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    submitInfo: {
      name: '',
      card: '',
      phone: '',
      wechat: '',
      bankNumbar: '',
      banKh: '',
      recommend: '',
      score: 0,
      isNextEnable: false
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    //业务埋点
    ubt_js.myPageView(common_js.currentPageName(), options);
    //1.禁止转发
    wx.hideShareMenu();
  },
  
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {
    // 业务埋点
    ubt_js.myPageViewOut(common_js.currentPageName());
  },

  //真实姓名
  onName: function(e) {
    var tmp = e.detail.content;
    var tmpSubmitInfo = this.data.submitInfo;
    if (tmpSubmitInfo.name.length == 0 && tmp.length > 0) {
      tmpSubmitInfo.score++;
    } else if (tmpSubmitInfo.name.length > 0 && tmp.length == 0) {
      tmpSubmitInfo.score--;
    }
    tmpSubmitInfo.name = tmp;
    if (tmpSubmitInfo.score == 6) {
      tmpSubmitInfo.isNextEnable = true;
    } else {
      tmpSubmitInfo.isNextEnable = false;
    }
    this.setData({
      submitInfo: tmpSubmitInfo
    });
  },

  //身份证号
  onCard: function(e) {
    var tmp = e.detail.content;
    var tmpSubmitInfo = this.data.submitInfo;
    if (tmpSubmitInfo.card.length == 0 && tmp.length > 0) {
      tmpSubmitInfo.score++;
    } else if (tmpSubmitInfo.card.length > 0 && tmp.length == 0) {
      tmpSubmitInfo.score--;
    }
    tmpSubmitInfo.card = tmp;
    if (tmpSubmitInfo.score == 6) {
      tmpSubmitInfo.isNextEnable = true;
    } else {
      tmpSubmitInfo.isNextEnable = false;
    }
    this.setData({
      submitInfo: tmpSubmitInfo
    });
  },

  //手机号
  onPhone: function(e) {
    var tmp = e.detail.content;
    var tmpSubmitInfo = this.data.submitInfo;
    if (tmpSubmitInfo.phone.length == 0 && tmp.length > 0) {
      tmpSubmitInfo.score++;
    } else if (tmpSubmitInfo.phone.length > 0 && tmp.length == 0) {
      tmpSubmitInfo.score--;
    }
    tmpSubmitInfo.phone = tmp;
    if (tmpSubmitInfo.score == 6) {
      tmpSubmitInfo.isNextEnable = true;
    } else {
      tmpSubmitInfo.isNextEnable = false;
    }
    this.setData({
      submitInfo: tmpSubmitInfo
    });
  },

  //微信号
  onWechat: function(e) {
    var tmp = e.detail.content;
    var tmpSubmitInfo = this.data.submitInfo;
    if (tmpSubmitInfo.wechat.length == 0 && tmp.length > 0) {
      tmpSubmitInfo.score++;
    } else if (tmpSubmitInfo.wechat.length > 0 && tmp.length == 0) {
      tmpSubmitInfo.score--;
    }
    tmpSubmitInfo.wechat = tmp;
    if (tmpSubmitInfo.score == 6) {
      tmpSubmitInfo.isNextEnable = true;
    } else {
      tmpSubmitInfo.isNextEnable = false;
    }
    this.setData({
      submitInfo: tmpSubmitInfo
    });
  },

  //银行卡号
  onBankNumber: function(e) {
    var tmp = e.detail.content;
    var tmpSubmitInfo = this.data.submitInfo;
    if (tmpSubmitInfo.bankNumbar.length == 0 && tmp.length > 0) {
      tmpSubmitInfo.score++;
    } else if (tmpSubmitInfo.bankNumbar.length > 0 && tmp.length == 0) {
      tmpSubmitInfo.score--;
    }
    tmpSubmitInfo.bankNumbar = tmp;
    if (tmpSubmitInfo.score == 6) {
      tmpSubmitInfo.isNextEnable = true;
    } else {
      tmpSubmitInfo.isNextEnable = false;
    }
    this.setData({
      submitInfo: tmpSubmitInfo
    });
  },

  //开户行名称
  onBankKh: function(e) {
    var tmp = e.detail.content;
    var tmpSubmitInfo = this.data.submitInfo;
    if (tmpSubmitInfo.banKh.length == 0 && tmp.length > 0) {
      tmpSubmitInfo.score++;
    } else if (tmpSubmitInfo.banKh.length > 0 && tmp.length == 0) {
      tmpSubmitInfo.score--;
    }
    tmpSubmitInfo.banKh = tmp;
    if (tmpSubmitInfo.score == 6) {
      tmpSubmitInfo.isNextEnable = true;
    } else {
      tmpSubmitInfo.isNextEnable = false;
    }
    this.setData({
      submitInfo: tmpSubmitInfo
    });
  },

  //您的推荐人
  onRecommed: function(e) {
    var tmp = e.detail.content;
    var tmpSubmitInfo = this.data.submitInfo;
    tmpSubmitInfo.recommend = tmp;
    this.setData({
      submitInfo: tmpSubmitInfo
    });
  },

  //下一步
  onNext: function(e) {
    //1.是否可以点击下一步
    if (!this.data.submitInfo.isNextEnable) return;
    //2.身份证号位数
    if (this.data.submitInfo.card.length != 18) {
      common_js.showToast('请输入正确的身份证号!');
      return;
    }
    //3.手机号
    if (!common_js.isPhone(this.data.submitInfo.phone)) {
      common_js.showToast('请输入正确的手机号!');
      return;
    }
    //4.校验微信号是否含有汉字
    if (common_js.containsChinese(this.data.submitInfo.wechat)) {
      common_js.showToast('微信号不能含有汉字!');
      return;
    }
    //5.银行卡号
    if (this.data.submitInfo.bankNumbar.length == 0) {
      common_js.showToast('请输入正确的银行卡号!');
      return;
    }
    //6.跳转
    wx.navigateTo({
      url: '../tobeTzSecondStep/tobeTzSecondStep?dzInfo=' + common_js.jsonStringify(this.data.submitInfo)
    });

    //埋点
    ubt_js.myClickButton(common_js.currentPageName(), name_js.tobeTzFirstStepDone);
  }
})